import 'package:flutter/material.dart';
import '../../models/task.dart';
import '../../theme/app_theme.dart';

class StatsOverview extends StatelessWidget {
  final List<Task> tasks;
  final Animation<double> scaleAnimation;

  const StatsOverview({
    Key? key,
    required this.tasks,
    required this.scaleAnimation,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final totalTasks = tasks.length;
    final completedTasks = tasks.where((task) => task.isCompleted).length;
    final pendingTasks = totalTasks - completedTasks;
    final completionRate = totalTasks > 0 ? (completedTasks / totalTasks * 100) : 0;

    return ScaleTransition(
      scale: scaleAnimation,
      child: Container(
        margin: const EdgeInsets.only(bottom: AppTheme.paddingXXL),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text(
              "任务概览",
              style: TextStyle(
                fontSize: AppTheme.fontSizeXL,
                fontWeight: FontWeight.bold,
                color: AppTheme.textPrimaryColor,
              ),
            ),
            const SizedBox(height: AppTheme.paddingL),
            Row(
              children: [
                Expanded(child: _buildStatCard("总任务", totalTasks.toString(), Icons.assignment_outlined, AppTheme.primaryGradient)),
                const SizedBox(width: AppTheme.paddingM),
                Expanded(child: _buildStatCard("已完成", completedTasks.toString(), Icons.check_circle_outline, AppTheme.successGradient)),
              ],
            ),
            const SizedBox(height: AppTheme.paddingM),
            Row(
              children: [
                Expanded(child: _buildStatCard("待完成", pendingTasks.toString(), Icons.pending_outlined, AppTheme.warningGradient)),
                const SizedBox(width: AppTheme.paddingM),
                Expanded(child: _buildStatCard("完成率", "${completionRate.toStringAsFixed(0)}%", Icons.trending_up_outlined, 
                  completionRate >= 80 ? AppTheme.successGradient : completionRate >= 50 ? AppTheme.warningGradient : 
                  const LinearGradient(colors: [Color(0xFFEF4444), Color(0xFFDC2626)]))),
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildStatCard(String title, String value, IconData icon, LinearGradient gradient) {
    return Container(
      padding: const EdgeInsets.all(AppTheme.paddingL),
      decoration: BoxDecoration(
        gradient: const LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: [Colors.white, Color(0xFFFAFBFF)],
        ),
        borderRadius: BorderRadius.circular(AppTheme.radiusL),
        boxShadow: AppTheme.softShadow,
        border: Border.all(
          color: Colors.white.withOpacity(0.6),
          width: 1,
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: const EdgeInsets.all(8),
            decoration: BoxDecoration(
              gradient: gradient,
              borderRadius: BorderRadius.circular(8),
            ),
            child: Icon(
              icon,
              color: Colors.white,
              size: 20,
            ),
          ),
          const SizedBox(height: AppTheme.paddingM),
          Text(
            value,
            style: const TextStyle(
              fontSize: AppTheme.fontSizeXL,
              fontWeight: FontWeight.bold,
              color: AppTheme.textPrimaryColor,
            ),
          ),
          Text(
            title,
            style: const TextStyle(
              fontSize: AppTheme.fontSizeS,
              color: AppTheme.textSecondaryColor,
              fontWeight: FontWeight.w500,
            ),
          ),
        ],
      ),
    );
  }
} 